﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FaceRecognition.Models;
using FaceRecognition.Utilities;
using FaceRecognition.Controller;

namespace FaceRecognition.View
{
    public partial class Form_DeleteUser : Form
    {
        User_Manager db;
        Controller_Class control;
      
        public Form_DeleteUser()
        {
            InitializeComponent();
            db=new User_Manager();
            control = new Controller_Class();
           

        }

        private void button1_Click(object sender, EventArgs e)
        {
          
            try
            {
                if (control.User.ID_Exist(Convert.ToInt32(deleted_id.Text)))

                {
                    control.Train.delete_features_of_certain_id(Convert.ToInt32(deleted_id.Text));
                    control.User.delete_user_info(Convert.ToInt32(deleted_id.Text));
                    //control.delete_user_info(Convert.ToInt32(deleted_id.Text));
                    MessageBox.Show("Succefully deleted ", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                    MessageBox.Show("This ID doesn't exist ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch
            {
                MessageBox.Show("We couldn't connect to the database ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
      
            if (!General_Usage.isEmail(e_mail.Text))
            {
                MessageBox.Show("This email is not valid ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
           try
           {
               if (control.User.email_exist(e_mail.Text))//nw the function return true  if it find the email and throw exception if 
               {
                   Int32 id = control.User.ID_retrival_by_email(e_mail.Text);
                   control.Train.delete_features_of_certain_id(id);
                   control.User.delete_user_info_by_email(e_mail.Text);
                   MessageBox.Show("Succefully deleted ", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);

               }
               else
                   MessageBox.Show("This email doesn't exist ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch
            {
                MessageBox.Show("We couldn't connect to the database ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        
    }
}
